package client

import (
	"context"
	"net/http"
	"wms/internal/svc"
	"wms/internal/types"
	"wms/model"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClientRemoveLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewClientRemoveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClientRemoveLogic {
	return &ClientRemoveLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ClientRemoveLogic) ClientRemove(req *types.ClientRequest) (resp *types.BaseResponse, err error) {
	resp = new(types.BaseResponse)
	//1.删除客户信息
	err = l.svcCtx.ClientModel.Delete(l.ctx, req.Id)
	if err != nil {
		if err == model.ErrNotFound {
			resp.Code = http.StatusNoContent
			resp.Msg = "客户不存在"
			return resp, nil
		}
		resp.Code = http.StatusInternalServerError
		resp.Msg = "服务内部错误"
		return resp, nil
	}

	resp.Code = http.StatusOK
	resp.Msg = "成功"
	return resp, nil
}
